package com.hwl.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwl.server.entity.MenuRole;
import com.hwl.server.mapper.MenuRoleMapper;
import com.hwl.server.pojo.RespBean;
import com.hwl.server.service.MenuRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author long
 * @since 2021-11-28
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements MenuRoleService {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public RespBean updateMenuRole(Integer rid, Integer[] mids) {
        baseMapper.delete(new QueryWrapper<MenuRole>().eq("rid", rid));
        if (null == mids || 0 == mids.length) { //表示用户只是进行了删除菜单
            return RespBean.success("菜单更新成功");
        }

        Integer result = baseMapper.insertRecord(rid, mids);
        if (mids.length == result) {
            return RespBean.success("菜单更新成功");
        }
        return RespBean.error("菜单更新失败");
    }
}
